package c.e.a.b.e.c;

import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.StrictMode;
import android.os.StrictMode.ThreadPolicy;
import android.util.Log;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

/* compiled from: com.google.android.gms:play-services-measurement-impl@@18.0.0 */
public final /* synthetic */ class k2 implements z2 {
    public final Context a;

    public k2(Context context) {
        this.a = context;
    }

    public final Object q() {
        Context context = this.a;
        String str = "HermeticFileOverrides";
        x2 x2Var = w2.a;
        String str2 = Build.TYPE;
        String str3 = Build.TAGS;
        Object obj = ((str2.equals("eng") || str2.equals("userdebug")) && (str3.contains("dev-keys") || str3.contains("test-keys"))) ? 1 : null;
        if (obj == null) {
            return x2Var;
        }
        x2 y2Var;
        if (w1.a() && !context.isDeviceProtectedStorage()) {
            context = context.createDeviceProtectedStorageContext();
        }
        ThreadPolicy allowThreadDiskReads = StrictMode.allowThreadDiskReads();
        try {
            StrictMode.allowThreadDiskWrites();
            File file = new File(context.getDir("phenotype_hermetic", 0), "overrides.txt");
            y2Var = file.exists() ? new y2(file) : x2Var;
            StrictMode.setThreadPolicy(allowThreadDiskReads);
        } catch (RuntimeException e) {
            Log.e(str, "no data dir", e);
            StrictMode.setThreadPolicy(allowThreadDiskReads);
            y2Var = x2Var;
        } catch (Throwable th) {
            StrictMode.setThreadPolicy(allowThreadDiskReads);
            throw th;
        }
        if (!y2Var.b()) {
            return x2Var;
        }
        File file2 = (File) y2Var.c();
        BufferedReader bufferedReader;
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file2)));
            HashMap hashMap = new HashMap();
            while (true) {
                str3 = bufferedReader.readLine();
                if (str3 != null) {
                    String[] split = str3.split(" ", 3);
                    String str4;
                    if (split.length != 3) {
                        str4 = "Invalid: ";
                        Log.e(str, str3.length() != 0 ? str4.concat(str3) : new String(str4));
                    } else {
                        Object obj2 = split[0];
                        String decode = Uri.decode(split[1]);
                        str4 = Uri.decode(split[2]);
                        if (!hashMap.containsKey(obj2)) {
                            hashMap.put(obj2, new HashMap());
                        }
                        ((Map) hashMap.get(obj2)).put(decode, str4);
                    }
                } else {
                    String valueOf = String.valueOf(file2);
                    StringBuilder stringBuilder = new StringBuilder(valueOf.length() + 7);
                    stringBuilder.append("Parsed ");
                    stringBuilder.append(valueOf);
                    Log.i(str, stringBuilder.toString());
                    h2 h2Var = new h2(hashMap);
                    bufferedReader.close();
                    return new y2(h2Var);
                }
            }
        } catch (IOException e2) {
            throw new RuntimeException(e2);
        } catch (Throwable th2) {
            g3.a.a(th, th2);
        }
        throw th;
    }
}
